package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.RegisterDao;
import ysq.xyg.model.Register;
import ysq.xyg.service.RegisterService;
import ysq.xyg.util.EasyPoiUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("registerService")
public class RegisterServiceImpl extends BaseServiceImpl<Register> implements RegisterService {
    @Resource
    private RegisterDao registerDao;

    @Autowired
    public void setBaseDao(RegisterDao registerDao) {
        this.baseDao = registerDao;
    }

    @Override
    public PageInfo<Register> pageInfo(Register register, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(Register.class);
        Example.Criteria criteria = example.createCriteria();
        List<Register> list=registerDao.selectByExample(example);
        return new PageInfo<Register>(list);
    }
    @Override
    public List<Register> list(Register register) {
        //通用Example查询
        Example example = new Example(Register.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(register.getMonth())) {
            criteria.andEqualTo("month",register.getMonth());
        }
        if (StringUtil.isNotEmpty(register.getWangWang())) {
            criteria.andEqualTo("wangWang",register.getWangWang().trim());
        }
        if (StringUtil.isNotEmpty(register.getRemoveTag())) {
            criteria.andEqualTo("removeTag",register.getRemoveTag().trim());
        }
        List<Register> list=registerDao.selectByExample(example);
        return list;
    }
    public PageInfo<Register> pageLeft(Register register, int pageSize, int pageNum){
        PageHelper.startPage(pageNum,pageSize);
        List<Register> list=registerDao.listLeft(register);
        return new PageInfo<Register>(list);
    }
    /**
     *@Author: YuShengQiang
     *@Date: 2018-12-05 16:16
     *@Description:数据导出
     */
    @Override
    public void export(HttpServletResponse response, Register register) {
        String title="资料登记";
        List<Register> list=registerDao.listLeft(register);
        // 导出操作
        EasyPoiUtil.exportExcel(list, title, "资料登记信息", Register.class, title+".xls", response);
    }
}
